package com.Register.controller.user;


import com.Register.dto.ActivityPageQueryDTO;
import com.Register.dto.EnrollActivityDTO;
import com.Register.dto.MyActivityPageQueryDTO;
import com.Register.result.PageResult;
import com.Register.result.Result;
import com.Register.service.VolunteerActivityService;
import com.Register.vo.SearchActivityByIdVO;
import com.fasterxml.jackson.core.JsonProcessingException;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

@Tag(name="小程序端活动接口")
@RestController("AppletActivityController")
@RequestMapping("/applet/user/activity")
@Slf4j
public class VolunteerActivityController {

    @Resource
    private VolunteerActivityService volunteerActivityService;

    /**
     * 分页查询活动
     * @param activityPageQueryDTo
     * @return
     */
    @Operation(summary = "分页查询活动")
    @GetMapping("/activityPage")
    public Result<PageResult> VolunteerActivityPageQuery(@ParameterObject ActivityPageQueryDTO activityPageQueryDTo) throws JsonProcessingException {
        log.info("进行活动分页查询，查询参数为:{}",activityPageQueryDTo);
        return Result.success(volunteerActivityService.ActivityPageQuery(activityPageQueryDTo));
    }

    /**
     * 我的活动分页查询
     */
    @Operation(summary = "我的活动分页查询")
    @GetMapping("/myActivityPage")
    public Result<PageResult> myActivityPageQuery(@ParameterObject MyActivityPageQueryDTO myActivityPageQueryDTO){
        log.info("进行我的活动分页查询,参数为:{}",myActivityPageQueryDTO);
        return Result.success(volunteerActivityService.getActivitiesByUserId(myActivityPageQueryDTO.getCurrentPage(),
                myActivityPageQueryDTO.getPageSize(),
                myActivityPageQueryDTO.getStatus()));
    }

    /**
     *
     * 根据id查询活动
     * @param id
     * @return
     */
    @Operation(summary = "根据id查询活动")
    @GetMapping("/activity/{id}")
    public Result<SearchActivityByIdVO> searchActivityById(@PathVariable("id") Long id){
        return Result.success(volunteerActivityService.searchActivityById(id));
    }

    /**
     * 用户报名志愿活动
     * @param enrollActivityDTO
     * @return
     */
    @Operation(summary = "用户报名志愿活动")
    @PostMapping("/enrollActivity")
    public Result<String> userEnrollActivity(@RequestBody EnrollActivityDTO enrollActivityDTO){
        return volunteerActivityService.EnrollActivity(enrollActivityDTO);
    }

    /**
     * 用户取消报名志愿活动
     */
    @Operation(summary = "用户取消报名志愿活动")
    @PutMapping("/quitActivity")
    public Result<String> userQuitActivity(@RequestBody EnrollActivityDTO enrollActivityDTO){
        return volunteerActivityService.quitActivity(enrollActivityDTO);
    }

}
